package com.suez.eimsserver.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DbUtil {
	private static String className  ="oracle.jdbc.OracleDriver";
	private static String url = "jdbc:oracle:thin:@ITA-031-W7:1521:XE";
	private static String user ="emma";
	private static String pwd = "emma";

	static{
		try {
			Class.forName(className);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static Connection getConnection(){
		Connection connection=null;
		try{
			connection =DriverManager.getConnection(url, user, pwd);
		}catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return connection;
	}

	public static void freeConn(Connection connection) {
		try {
			
			if(connection!=null){
				connection.close();
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static void freeRS(ResultSet rs) {
		try {
			if(rs!=null){
				rs.close();
			}			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static void freePre(PreparedStatement pst) {
		try {			
			if(pst!=null){
				pst.close();
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
